package com.LatitudeYao;
import java.io.*;
import java.io.PipedReader;
import java.io.PipedWriter;

/**
 * Created by GTS on 2017/9/11.
 */
public class Piped {
    public static void main(String[] args) throws Exception{
        PipedWriter out = new PipedWriter();
        PipedReader in = new PipedReader();
        out.connect(in);
        Thread printThread = new Thread(new Print(in),"PrintThread");
        printThread.start();

        int re;
        try{
            while ((re=System.in.read())!=-1){
                out.write(re);
            }
        }
        finally {
            out.close();
        }

    }
    static class Print implements Runnable{
        private PipedReader in;
        public Print(PipedReader in){
            this.in = in;
        }
        @Override
        public void run(){
            int re=0;
            try{
                while ((re = in.read())!=-1){
                    System.out.print((char)re);
                }
            }
            catch (IOException ex){
                System.out.println("IOException ");
            }
        }
    }
}
